<%@page import="drukarnia.model.PriceForMaterials"%>
<%@page import="java.util.List"%>
<%@page import="drukarnia.controller.PriceForMaterialsManager"%>
<%@ page import="drukarnia.model.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page errorPage="WEB-INF/bledy.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Drukarnia</title>
</head>
<body>
<%
			String message = request.getParameter("message");
			if(message != null){ %>
				<h3 style="color:white; text-align:center; background-color: red">
				
				<% out.println(message);
			}	
		%></h3>
<h1>Materiały:</h1>
<h2><a href="addMaterial.jsp">Dodaj Materiał</a></h2>
<%
User user = (User)session.getAttribute("user");
if(user != null && user.getAuthorization() == 'a'){
	PriceForMaterialsManager man = new PriceForMaterialsManager();
	List<PriceForMaterials> p4mList = man.fetchPriceFromDB();
	String empty = "";
	if(p4mList.isEmpty()){
		
%>
		
		<h1>Brak materiałów.</h1>
		
<%		
	}else{
		
%>
		
			<center><table>
				<tr>
					<th>Nazwa materiału </th>
					<th>Cena za m2 </th>
					<th colspan="2">Edycja </th>
				</tr>
				<% for(PriceForMaterials price : p4mList){ %>
				<tr>
					<td><%= price.getTypeOfMaterial() %></td>
					<td><%= price.getPrice() %> zł</td>
					<td><a href="addMaterial.jsp?id=<%= price.getId_price() %>">edytuj</a></td>
					<td><a href="deleteMaterial.jsp?id=<%= price.getId_price() %>">usuń</a></td>
				</tr>
				<%} %>
			</table>
		</center>
	<br />
	<h2><a href="index.jsp">Powrót</a></h2>
		
	 <%
		} 
	 %>
	 <% }else{
		 response.sendError(404,"Drukarnia: brak uprawnien");
	 	}
		 %>

</body>
</html>